1
1
.
.
9
9
C
C
O
O
R
R
S
S
(
(
C
C
r
r
o
o
s
s
s
s
O
O
r
r
i
i
g
g
i
i
n
n
R
R
e
e
s
s
o
o
u
u
r
r
c
c
e
e
S
S
h
h
a
a
r
r
i
i
n
n
g
g
)
)
I
I
n
n
f
f
o
o
[
[
R
R
]
]
[
[
R
R
]
]
CORS stands for Cross Origin Resource Sharing.
CORS is when Java Script tries to access resource from another Origin/Application.
And not from Origin/Application which served the HTML Page with that Java Script.
Origin/Application includes combination of Protocol, Domain and Port
so if HTML containing Java Script was served from http://localhost:8080/Hello.html
and Java Script from that Page tries to access image at http://localhost:8085/SomeImage.png
then these two URLs represent different Origins/Applications (because they listen at different Ports 8080 vs 8085)
Java Script runs inside Browsers which by default disables CORS.
So if your Spring Boot Application returns HTML Page that contains Java Script that needs to access resource from
another Origin/Application then you need to enable CORS on destination Application (one that contains that resource).
This means that in order to demonstrate CORS we need to create two Spring Boot Applications
Source Application will run on Port 8080 and it will contain HTML with Java Script calling Destination Application
Destination Application will run on Port 8085 and here we need to enable CORS
CORS Schema
Source
Application
Destination
Application
Enable CORS
HTML with JavaScript
http://localhost:8080/Hello
http://localhost:8085/Hello
Call Resource
from JavaScript